# 字典


# 字典的创建
zips = {'a':10,'b':20,'c':40}
print(zips)

lst1 = [1,2,3,4,5]
lst2 = ['a','b','c','d','e']
zips2 = zip(lst1,lst2)
print(zips2,'----zip2s') #返回是一个字典对象
zips2 = list(zips2)
print(zips2,'===list') #返回一个列表，并且每个元素是一个元组
zips2 = dict(zips2) #转换为字典类型
print(zips2,'--dict')

# 访问字典
print(zips.keys())
print(zips.values())
print(zips['a'])
print(zips.get('b'))
# print(zips['ef']) 报错
print(zips.get('ef')) #没有的对象可以返回None
print(zips.get('ef'),'no found ef') # 查找未定义的key，还可以返回一个默认的提示信息

# pop删除key-value, 如果key存在则删除key-value,并返回key所对应的value，否则返回第二个参数
res = zips.pop('a','no funon')
print(zips,'==>',res)
res = zips.pop('ef','no found ef')
print(zips,'==>',res)

# 随机删除一个
res2 = zips.popitem()
print(zips,'==>',res2)

# 清空
zips.clear()
print(zips)

#字典的遍历
zips10 = {'a':10,'b':20,'c':30}
for item in zips10.values():
    print(item)
for key ,item in zips10.items():
    print(key ,item )
for item in zips10.keys():
    print(item,'-->',zips10.get(item))
    print(item,'===>', zips10[item])
for key, item in enumerate(zips10.items()):
    print(item[0],'+++>',item[1])